package com.location.footprint.adapter

import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.location.footprint.R
import com.location.footprint.bean.ThemeBean
import com.location.footprint.utils.Utils


class ThemeAdapter : BaseQuickAdapter<ThemeBean, BaseViewHolder>(R.layout.item_theme_list) {

    override fun convert(helper: BaseViewHolder, item: ThemeBean) {
        var img_radio = helper.getView<ImageView>(R.id.radio_theme)
        var img_radio_bg = img_radio!!.getBackground() as GradientDrawable

        if (helper.layoutPosition == 0) {
            img_radio_bg.setColor(ContextCompat.getColor(mContext, R.color.text_cancel))
            img_radio!!.background = img_radio_bg

            var text_use = helper.getView<TextView>(R.id.text_theme_use)
            var text_use_background = text_use!!.getBackground() as GradientDrawable

            helper.setText(R.id.text_theme_content, item.content)
            if (item.select!!) {
                helper.setText(R.id.text_theme_use, "使用中")
            } else {
                helper.setText(R.id.text_theme_use, "使用")
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                img_radio.foreground = null
                text_use_background.setStroke(Utils.dip2px(mContext, 1), ContextCompat.getColor(mContext, R.color.text_cancel))
                text_use.setTextColor(ContextCompat.getColor(mContext, R.color.text_cancel))
            }
        } else {
            img_radio_bg.setColor(ContextCompat.getColor(mContext, item.color!!))
            img_radio!!.background = img_radio_bg

            var text_use = helper.getView<TextView>(R.id.text_theme_use)
            var text_use_background = text_use!!.getBackground() as GradientDrawable

            helper.setText(R.id.text_theme_content, item.content)
            if (item.select!!) {
                helper.setText(R.id.text_theme_use, "使用中")
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    img_radio.foreground = ContextCompat.getDrawable(mContext, R.mipmap.ic_theme_check)
                    text_use_background.setStroke(Utils.dip2px(mContext, 1), ContextCompat.getColor(mContext, item.color!!))
                    text_use.setTextColor(ContextCompat.getColor(mContext, item.color!!))
                }

            } else {
                helper.setText(R.id.text_theme_use, "使用")
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    img_radio.foreground = null
                    text_use_background.setStroke(Utils.dip2px(mContext, 1), ContextCompat.getColor(mContext, R.color.text_cancel))
                    text_use.setTextColor(ContextCompat.getColor(mContext, R.color.text_cancel))
                }
            }
        }


        //        ImageView imageView = helper.getView(R.id.image);
        //        imageView.setBackgroundResource(item.getImage());
        //        GlideUtils.loadImageViewSize(this.mContext, item.getImage(), Utils.dip2px(65, this.mContext), Utils.dip2px(130, this.mContext), imageView);
    }


}
